

************** Spatial approach, 6: Regressions ******************
* spatial transformation completed previously in spatial_1_* - spatial_5_*

************************************
* Contents
		* Radiant based: section 2 horizontal, 6 vertical, counter-clockwise.
		* 4950 cells based on k_bins of width 3 KwH 
		* Outcomes: sales and count, each in level, log+1, and ihs transformation
		* standard errors clustered by cell   
************************************

************************************
* Variables
		* cm: country-month items (second level identifier)
		* cell: 1-50 are bunchers at window = 2. (primary identifier)
		* a_bin/e_bin: individual attributes, unstandardized 
		* csd  / ccd: sales / product count in cell. 
		

 clear
 capture log close
 set more off
 
capture mkdir Data
global store "R:\WSV2\TBu_AKe\Spatial_NEW\Data"
 
cd "R:\WSV2\TBu_AKe\Spatial_NEW"

log using spatial_6_regs_s_2703, replace   

cd // display in log 
		
			***************************
			* run regression: OLS, fe *
			***************************		
		
use spatial_regs_s_monthly, replace		
	
			*** Outcome #1 : sales 
			
keep if year == 2014 // no changes. otherwise matrices are wrong in previous. 	
	
	
			***************************
			***** Single Matrix *****
			***************************	
		

** log and ihs transformations to the untransformed data **

		*** outcomes and polar cases (no q indexing needed, only double loop)
foreach varx of varlist csd L3_sd  		ccd L3_cd     {

   gen     log_`varx'=log(1+`varx')
   gen     ihs_`varx'=`varx'+(`varx'^2+1)^0.5
   replace ihs_`varx'=log(ihs_`varx')
 }
 
 
		*** spatial variables *** 
forvalues q = 1(1)8 { 
	foreach varx of varlist 	S`q'_L3_sd C`q'_L3_sd B`q'_L3_sd S`q'_L3_cd C`q'_L3_cd B`q'_L3_cd	{

   gen     log_`varx'=log(1+`varx')
   gen     ihs_`varx'=`varx'+(`varx'^2+1)^0.5
   replace ihs_`varx'=log(ihs_`varx')
	}
}



			**********************************************
			***** 			Regressions 			 *****
			**********************************************

			
***************** OUTCOME SALES LEVEL ****************************

		
		******************
		*** Fan (S) ******
		******************

	** Results for untransformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  csd    L3_sd 	S`q'_L3_sd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store fe2_S`q'
}


    ** Results for log transformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  log_csd    log_L3_sd 	log_S`q'_L3_sd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store log_fe2_S`q'
}


    ** Results for ihs transformed data **

			 
forvalues q = 1(1)8 {
	reghdfe  ihs_csd    ihs_L3_sd 	ihs_S`q'_L3_sd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store ihs_fe2_S`q'
}



***************** OUTCOME Count ****************************
	

	** Results for untransformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  ccd    L3_cd 	S`q'_L3_cd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store feC_S`q'
}


    ** Results for log transformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  log_ccd    log_L3_cd 	log_S`q'_L3_cd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store log_feC_S`q'
}


    ** Results for ihs transformed data **

			 
forvalues q = 1(1)8 {
	reghdfe  ihs_ccd    ihs_L3_cd 	ihs_S`q'_L3_cd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store ihs_feC_S`q'
}

		********************
		** report results **
		********************
		
		******* reghdfe LEVEL w/ country and cell fixed-effects ******
					
estimates table fe2_S*, b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe LOG w/ country and cell fixed-effects ******
					
estimates table  log_fe2_S* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe IHS w/ country and cell fixed-effects ******

estimates table  ihs_fe2_S* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)


		******* reghdfe for product count as outcome *************

/* 
		******* reghdfe LEVEL w/ country and cell fixed-effects ******
					
estimates table feC_S*, b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe LOG w/ country and cell fixed-effects ******
					
estimates table  log_feC_S* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe IHS w/ country and cell fixed-effects ******

estimates table  ihs_feC_S* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

*/ 

		************************
		*** 4 corners (C) ******
		************************
		
	***************** OUTCOME Sales ****************************

	** Results for untransformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  csd    L3_sd 	C`q'_L3_sd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store fe2_C`q'
}


    ** Results for log transformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  log_csd    log_L3_sd 	log_C`q'_L3_sd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store log_fe2_C`q'
}


    ** Results for ihs transformed data **

			 
forvalues q = 1(1)8 {
	reghdfe  ihs_csd    ihs_L3_sd 	ihs_C`q'_L3_sd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store ihs_fe2_C`q'
}


***************** OUTCOME Count ****************************
	

	** Results for untransformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  ccd    L3_cd 	C`q'_L3_cd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store feC_C`q'
}


    ** Results for log transformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  log_ccd    log_L3_cd 	log_C`q'_L3_cd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store log_feC_C`q'
}


    ** Results for ihs transformed data **

			 
forvalues q = 1(1)8 {
	reghdfe  ihs_ccd    ihs_L3_cd 	ihs_C`q'_L3_cd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store ihs_feC_C`q'
}


		********************
		** report results **
		********************
		
		*** outcome sales 
		
		******* reghdfe LEVEL w/ country and cell fixed-effects ******
					
estimates table fe2_C*, b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe LOG w/ country and cell fixed-effects ******
					
estimates table  log_fe2_C* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe IHS w/ country and cell fixed-effects ******

estimates table  ihs_fe2_C* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)


		******* reghdfe for product count as outcome *************

/* 
		******* reghdfe LEVEL w/ country and cell fixed-effects ******
					
estimates table feC_C*, b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe LOG w/ country and cell fixed-effects ******
					
estimates table  log_feC_C* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe IHS w/ country and cell fixed-effects ******

estimates table  ihs_feC_C* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

*/ 

		************************
		*** Beam (B) ***********
		************************
		
	***************** OUTCOME Sales ****************************

	** Results for untransformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  csd    L3_sd 	B`q'_L3_sd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store fe2_B`q'
}


    ** Results for log transformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  log_csd    log_L3_sd 	log_B`q'_L3_sd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store log_fe2_B`q'
}


    ** Results for ihs transformed data **

			 
forvalues q = 1(1)8 {
	reghdfe  ihs_csd    ihs_L3_sd 	ihs_B`q'_L3_sd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store ihs_fe2_B`q'
}


***************** OUTCOME Count ****************************
	

	** Results for untransformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  ccd    L3_cd 	B`q'_L3_cd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store feC_B`q'
}


    ** Results for log transformed data **
			 
forvalues q = 1(1)8 {
	reghdfe  log_ccd    log_L3_cd 	log_B`q'_L3_cd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store log_feC_B`q'
}


    ** Results for ihs transformed data **

			 
forvalues q = 1(1)8 {
	reghdfe  ihs_ccd    ihs_L3_cd 	ihs_B`q'_L3_cd					if cell <= 50 & year == 2014, absorb(cell ccode month) vce(cluster cell) 
	estimates store ihs_feC_B`q'
}


		********************
		** report results **
		********************
		
		*** outcome sales 
		
		******* reghdfe LEVEL w/ country and cell fixed-effects ******
					
estimates table fe2_B*, b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe LOG w/ country and cell fixed-effects ******
					
estimates table  log_fe2_B* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe IHS w/ country and cell fixed-effects ******

estimates table  ihs_fe2_B* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)


		******* reghdfe for product count as outcome *************
/* 

		******* reghdfe LEVEL w/ country and cell fixed-effects ******
					
estimates table feC_B*, b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe LOG w/ country and cell fixed-effects ******
					
estimates table  log_feC_B* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe IHS w/ country and cell fixed-effects ******

estimates table  ihs_feC_B* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

*/ 

log close 


log using results_summary_s_2703_monthly, replace 

		********************
		** report results **
		********************
		
		** SETUP : cmx = 4950, matrix = fan/beam/4corners, date = monthly, FE = cell, month, ccode 
		
		**************
		** Fan (S) **
		*************
		
	
		*** outcome sales 
		
		******* reghdfe LEVEL w/ country and cell fixed-effects ******
					
estimates table fe2_S*, b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe LOG w/ country and cell fixed-effects ******
					
estimates table  log_fe2_S* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe IHS w/ country and cell fixed-effects ******

estimates table  ihs_fe2_S* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)



		*******************
		** 4 Corners (C) **
		*******************
		
		*** outcome sales 
		
		******* reghdfe LEVEL w/ country and cell fixed-effects ******
					
estimates table fe2_C*, b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe LOG w/ country and cell fixed-effects ******
					
estimates table  log_fe2_C* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe IHS w/ country and cell fixed-effects ******

estimates table  ihs_fe2_C* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)



		**************
		** Beam (B) **
		*************
		
		*** outcome sales 
		
		******* reghdfe LEVEL w/ country and cell fixed-effects ******
					
estimates table fe2_B*, b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe LOG w/ country and cell fixed-effects ******
					
estimates table  log_fe2_B* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)

		******* reghdfe IHS w/ country and cell fixed-effects ******

estimates table  ihs_fe2_B* , b(%9.4f) stats(N r2 r2_a F) star(0.10 .05 .01)


log close 

clear 

exit 

/*

cd "R:\WSV2\TBu_AKe\Product Ban\Tex" // export output tables 
		
esttab log_fe2_B6 log_fe2_B2 log_fe2_B1 log_fe2_B3 log_fe2_B4 log_fe2_B5 log_fe2_B7 log_fe2_B8 using log_B.tex, noconstant b(%9.3f) se(%9.3f) stats(r2) star(* 0.10 ** .05 *** .01) nogap mtitles title(Logarithm Beam table\label{log_B}) replace
 		
esttab log_fe2_S6 log_fe2_S2 log_fe2_S1 log_fe2_S3 log_fe2_S4 log_fe2_S5 log_fe2_S7 log_fe2_S8 using log_S.tex, noconstant b(%9.3f) se(%9.3f) stats(r2) star(* 0.10 ** .05 *** .01) nogap mtitles title(Logarithm Fan table\label{log_S}) replace

esttab log_fe2_C6 log_fe2_C2 log_fe2_C1 log_fe2_C3 log_fe2_C4 log_fe2_C5 log_fe2_C7 log_fe2_C8 using log_C.tex, noconstant b(%9.3f) se(%9.3f) stats(r2) star(* 0.10 ** .05 *** .01) nogap mtitles title(Logarithm Corners table\label{log_C}) replace

esttab ihs_fe2_B6 ihs_fe2_B2 ihs_fe2_B1 ihs_fe2_B3 ihs_fe2_B4 ihs_fe2_B5 ihs_fe2_B7 ihs_fe2_B8 using ihs_B.tex, noconstant b(%9.3f) se(%9.3f) stats(r2) star(* 0.10 ** .05 *** .01) nogap mtitles title(Inverse Hyperbolic Sine Beam table\label{ihs_B}) replace
 		
esttab ihs_fe2_S6 ihs_fe2_S2 ihs_fe2_S1 ihs_fe2_S3 ihs_fe2_S4 ihs_fe2_S5 ihs_fe2_S7 ihs_fe2_S8 using ihs_S.tex, noconstant b(%9.3f) se(%9.3f) stats(r2) star(* 0.10 ** .05 *** .01) nogap mtitles title(Inverse Hyperbolic Sine Fan table\label{ihs_S}) replace

esttab ihs_fe2_C6 ihs_fe2_C2 ihs_fe2_C1 ihs_fe2_C3 ihs_fe2_C4 ihs_fe2_C5 ihs_fe2_C7 ihs_fe2_C8 using ihs_C.tex, noconstant b(%9.3f) se(%9.3f) stats(r2) star(* 0.10 ** .05 *** .01) nogap mtitles title(Inverse Hyperbolic Sine Corners table\label{ihs_C}) replace

	*** 4-digit R2
esttab log_fe2_B6 log_fe2_B2 log_fe2_B1 log_fe2_B3 log_fe2_B4 log_fe2_B5 log_fe2_B7 log_fe2_B8 using log_B_r2.tex, noconstant b(%9.4f) se(%9.4f) stats(r2) star(* 0.10 ** .05 *** .01) keep(log_L*) nogap mtitles title(Logarithm Beam table\label{r2_log_B}) replace
 		
esttab log_fe2_S6 log_fe2_S2 log_fe2_S1 log_fe2_S3 log_fe2_S4 log_fe2_S5 log_fe2_S7 log_fe2_S8 using log_S_r2.tex, noconstant b(%9.4f) se(%9.4f) stats(r2) star(* 0.10 ** .05 *** .01) keep(log_L*) nogap mtitles title(Logarithm Fan table\label{r2_log_S}) replace

esttab log_fe2_C6 log_fe2_C2 log_fe2_C1 log_fe2_C3 log_fe2_C4 log_fe2_C5 log_fe2_C7 log_fe2_C8 using log_C_r2.tex, noconstant b(%9.4f) se(%9.4f) stats(r2) star(* 0.10 ** .05 *** .01) keep(log_L*) nogap mtitles title(Logarithm Corners table\label{r2_log_C}) replace

esttab ihs_fe2_B6 ihs_fe2_B2 ihs_fe2_B1 ihs_fe2_B3 ihs_fe2_B4 ihs_fe2_B5 ihs_fe2_B7 ihs_fe2_B8 using ihs_B_r2.tex, noconstant b(%9.4f) se(%9.4f) stats(r2) star(* 0.10 ** .05 *** .01) keep(ihs_L*) nogap mtitles title(Inverse Hyperbolic Sine Beam table\label{r2_ihs_B}) replace
 		
esttab ihs_fe2_S6 ihs_fe2_S2 ihs_fe2_S1 ihs_fe2_S3 ihs_fe2_S4 ihs_fe2_S5 ihs_fe2_S7 ihs_fe2_S8 using ihs_S_r2.tex, noconstant b(%9.4f) se(%9.4f) stats(r2) star(* 0.10 ** .05 *** .01) keep(ihs_L*) nogap mtitles title(Inverse Hyperbolic Sine Fan table\label{r2_ihs_S}) replace

esttab ihs_fe2_C6 ihs_fe2_C2 ihs_fe2_C1 ihs_fe2_C3 ihs_fe2_C4 ihs_fe2_C5 ihs_fe2_C7 ihs_fe2_C8 using ihs_C_r2.tex, noconstant b(%9.4f) se(%9.4f) stats(r2) star(* 0.10 ** .05 *** .01) keep(ihs_L*) nogap mtitles title(Inverse Hyperbolic Sine Corners table\label{r2_ihs_C}) replace

*/
 